<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>数组的变异和替换</title>
</head>

<body>
    <div class="app">
        <div>
            <span>
                <input type="text" v-model="fname" v-on:keyup.enter="add">
            </span>
            <button @click="add">添加</button>
            <button @click="del">删除</button>
            <button @click="change">替换</button>
        </div>
        <ul>
            <li v-for="(item,index) in list" :key="item.id">{{ item }}</li>
        </ul>
    </div>
    <script src="./js/vue.js"></script>
    <script>
        var xm = new Vue({
            el: '.app',
            data: {
                fname: '',
                list: ['pear', 'banana', 'apple']
            },
            methods: {
                add: function () {
                    this.list.push(this.fname)
                    this.fname = ''
                },
                del: function () {
                    this.list.pop()
                },
                change: function () {
                    this.list = this.list.slice(0, 2)
                }
            }

        })

    </script>
</body>

</html>